/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package core;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import javax.swing.JFrame;

/**
 *
 * @author Maniek
 */
public class ZapisyTerminy {   
    public void addWizyta(User us, Doctor doc, int numer_gabinetu, Date from, Date to)
    {
        if(from.compareTo(to) > 0) {
           Date temp = to;
           to = from;
           from = temp;
        }
                
        try{ 
            PreparedStatement stmt = SqlConnection.getInstance().getSqlConnection().prepareStatement(
                    "INSERT INTO terminarz_wizyty_doktorskie VALUES(?,?,?,?,?)",
                    ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            stmt.setInt(1, us.getID());
            stmt.setInt(2, doc.getID());
            stmt.setInt(3, numer_gabinetu);
           
                stmt.setTimestamp(4, new java.sql.Timestamp(from.getTime()));
                stmt.setTimestamp(5, new java.sql.Timestamp(to.getTime()));

            stmt.executeUpdate();
        }
         catch(SQLException ex)
        {
            System.out.println("KURWA");
            ErrorLogger.getInstance().log(ex.getMessage(), true, us.getJFrameParent());
        }
    }
    
    public void delWizyta(User us, Doctor doc, Date from, Date to)
    {
        try{ 
            PreparedStatement stmt = SqlConnection.getInstance().getSqlConnection().prepareStatement(
                    "DELETE FROM terminarz_wizyty_doktorskie WHERE id_pacjenta='"+us.getID()+"' AND id_medyka='"+doc.getID()+"' AND data_start='"+new java.sql.Timestamp(from.getTime())+"' AND data_stop='"+new java.sql.Timestamp(to.getTime())+"'",
                   // "INSERT INTO terminarz_wizyty_doktorskie VALUES(?,?,?,?,?)",
                    ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);


            stmt.executeUpdate();
        }
         catch(SQLException ex)
        {
            ErrorLogger.getInstance().log(ex.getMessage(), true, us.getJFrameParent());
        }
    }
}
